package com.junray.mqttmanager

import java.io.Serializable
import java.util.Locale
import java.util.Random

class MQTTConfig : Serializable {

    var serverUri: String = ""  // 服务器地址
    var clientId: String = randomClientId() // 客户端ID，不能重复，默认为随机生成
    var subscriptionTopic: String = "" // 订阅主题
    var subscriptionTopics = arrayOf<String>() // 订阅多个主题
    var sendTopic: String = "" // 发送主题
    var userName: String = "" // 用户名
    var password: String = "" // 密码
    override fun toString(): String {
        return "MQTTRequest(serverUri='$serverUri', " +
                "clientId='$clientId', " +
                "subscriptionTopic='$subscriptionTopic', " +
                "subscriptionTopics='$subscriptionTopics', " +
                "sendTopic='$sendTopic', " +
                "userName='$userName', " +
                "password='$password')"
    }


    /**
     * 随机mac地址
     */
    private fun randomClientId(): String {
        val random = Random()
        val id = String.format(
            Locale.getDefault(), "%02X%02X%02X%02X%02X%02X",
            random.nextInt(256), random.nextInt(256), random.nextInt(256),
            random.nextInt(256), random.nextInt(256), random.nextInt(256)
        )
        return id
    }
}